package com.prime.tutorial.moviestore.view.testConfiguration;

import com.prime.tutorial.moviestore.Constants;
import com.prime.tutorial.moviestore.domain.Device;
import com.prime.tutorial.moviestore.domain.Model;
import com.prime.tutorial.moviestore.service.logicalview.LogicalTest;
import com.prime.tutorial.moviestore.service.testconfiguration.TestConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


import java.io.Serializable;
import java.util.List;


/**
 * Creates test configuration in database - groups, admin etc.
 * Created by IntelliJ IDEA.
 * Date: 21 лют 2010
 * Time: 14:15:18
 * @author iryna.masyuk
 */

@Component("createTestConfiguration")
@Scope("request")
public class CreateTestConfiguration implements Serializable {
    TestConfigurationService tcService;
    LogicalTest logicalTest;
    Device d;

    @Autowired
    public CreateTestConfiguration(TestConfigurationService tcService,
                                   LogicalTest logicalTest) {
        this.tcService = tcService;
        this.logicalTest = logicalTest;
    }
    public String createTestConfiguration() {
        tcService.createGroups();
        tcService.createAdmin();

        tcService.createDeviceStates();
        tcService.createModelTypes();
        tcService.createModels();

        d=null;
        
        return "login";
    }

    public String createPortTypes(){
        tcService.createPortTypes();

        return "login";
    }

    //---------------------------tests of logicalview methods------------------------------
    public List getCountriesWithDevices(){
       
        return logicalTest.getCountriesWithDevices();

    }
    public List getCitiesWithDevicesInUkraine(){
        return null;
    }
    public String addDeviceInKiev(){
       d = logicalTest.addDevice("aa",
                              Constants.MODEL_CPE_Cisco575LRECPE,
                              "Frolivska",
                              "13",
                              "234",
                              "wow",
                              "USA",
                              "Washington", 0, 0);


        return null;
    }

    public String addConnectionBetweenDevices(){
        Device one = logicalTest.addDevice("Dconnec1",
                Constants.MODEL_SWITCH_CiscoCatalyst2560V224TS,
                "Street1",
                "15",
                "23",
                "Dconnect1",
                "Ukraine",
                "Kiev",0.0,0.0);
        Device two = logicalTest.addDevice("Dconnec2",
                Constants.MODEL_SWITCH_CiscoCatalyst2560V224TS,
                "Street2",
                "17",
                "25",
                "Dconnect2",
                "Ukraine",
                "Kiev",0.0,0.0);

        logicalTest.addConnections(logicalTest.getDevicePortByDevice(one).get(0).getPort().getId().intValue(),
                                   logicalTest.getDevicePortByDevice(two).get(0).getPort().getId().intValue());
        return null;
    }

    public String addTestTopology(){
        //core router 1
        Device coreRouter =
                logicalTest.addDevice("CoreRouter1",
                        Constants.MODEL_ROUTER_CISCO3945,
                        "Yaroslaviv Val",
                        "12",
                        "124",
                        "CoreRouter1description",
                        "Ukraine",
                        "Kiev",
                        0,0);

        Device coreSwitch =
                logicalTest.addDevice("CoreSwitch1",
                        Constants.MODEL_SWITCH_CiscoCatalyst2560V248TS,
                        "Yaroslaviv Val",
                        "13",
                        "134",
                        "CoreSwitch1description",
                        "Ukraine",
                        "Kiev",
                        0,0);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreRouter).get(0).getPort().getId().intValue(),
                                           logicalTest.getDevicePortByDevice(coreSwitch).get(0).getPort().getId().intValue());

        Device lre1 =
                        logicalTest.addDevice("LRESwitch1",
                                Constants.MODEL_LRESWITCH_CiscoCatalyst2912LREXL,
                                "Ivana Franka",
                                "5",
                                "134",
                                "LRESwitch1description",
                                "Ukraine",
                                "Kiev",
                                50,50);
                         logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreSwitch).get(1).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(lre1).get(13).getPort().getId().intValue());

        Device cpe1 = logicalTest.addDevice("CPE1",
                                Constants.MODEL_CPE_Cisco575LRECPE,
                                "Pyrogova",
                                "7",
                                "76",
                                "CPE1description",
                                "Ukraine",
                                "Kiev",
                                50,50);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(lre1).get(0).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(cpe1).get(1).getPort().getId().intValue());


        Device cpe2 = logicalTest.addDevice("CPE2",
                                Constants.MODEL_CPE_Cisco575LRECPE,
                                "Leontovycha",
                                "11",
                                "9",
                                "CPE2description",
                                "Ukraine",
                                "Kiev",
                                60,60);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(lre1).get(2).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(cpe2).get(1).getPort().getId().intValue());

        Device cpe3 = logicalTest.addDevice("CPE3",
                                Constants.MODEL_CPE_Cisco575LRECPE,
                                "Lysenka",
                                "8",
                                "99",
                                "CPE3description",
                                "Ukraine",
                                "Kiev",
                                70,70);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(lre1).get(1).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(cpe3).get(1).getPort().getId().intValue());


        Device cpe4 = logicalTest.addDevice("CPE4",
                                Constants.MODEL_CPE_Cisco575LRECPE,
                                "Lysenka",
                                "6",
                                "999",
                                "CPE4description",
                                "Ukraine",
                                "Kiev",
                                80,80);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(lre1).get(4).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(cpe4).get(1).getPort().getId().intValue());


        Device coreSwitch2 =
                logicalTest.addDevice("CoreSwitch2",
                        Constants.MODEL_SWITCH_CiscoCatalyst2560V248TS,
                        "Ivana Franka",
                        "4",
                        "134",
                        "CoreSwitch2description",
                        "Ukraine",
                        "Kiev",
                        50,50);
                 logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreRouter).get(1).getPort().getId().intValue(),
                                           logicalTest.getDevicePortByDevice(coreSwitch2).get(0).getPort().getId().intValue());

        //core router 2
        Device coreRouter2 =
                        logicalTest.addDevice("CoreRouter2",
                                Constants.MODEL_ROUTER_CISCO3945,
                                "Patrisa Lumumby",
                                "7",
                                "124",
                                "CoreRouter2description",
                                "Ukraine",
                                "Kiev",
                                50,50);
        Device coreSwitch21 =
                        logicalTest.addDevice("CoreSwitch21",
                                Constants.MODEL_SWITCH_CiscoCatalyst2560V248TS,
                                "Patrisa Lumumby",
                                "5",
                                "134",
                                "CoreSwitch1description",
                                "Ukraine",
                                "Kiev",
                                0,0);
       logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreRouter2).get(0).getPort().getId().intValue(),
                                                   logicalTest.getDevicePortByDevice(coreSwitch21).get(0).getPort().getId().intValue());

        //core router 3
        Device coreRouter3 =
                                logicalTest.addDevice("CoreRouter3",
                                        Constants.MODEL_ROUTER_CISCO3945,
                                        "Nagirna",
                                        "12",
                                        "126",
                                        "CoreRouter3description",
                                        "Ukraine",
                                        "Kiev",
                                        50,50);
        Device coreSwitch31 =
                                logicalTest.addDevice("CoreSwitch31",
                                        Constants.MODEL_SWITCH_CiscoCatalyst2560V248TS,
                                        "Nagirna",
                                        "29",
                                        "134",
                                        "CoreSwitch31description",
                                        "Ukraine",
                                        "Kiev",
                                        0,0);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreRouter3).get(0).getPort().getId().intValue(),
                                                           logicalTest.getDevicePortByDevice(coreSwitch31).get(0).getPort().getId().intValue());


        Device LRESwitch311 =
                                logicalTest.addDevice("LreSwitch311",
                                        Constants.MODEL_LRESWITCH_CiscoCatalyst2912LREXL,
                                        "Otto Shmidta",
                                        "14",
                                        "55",
                                        "LreSwitch31description",
                                        "Ukraine",
                                        "Kiev",
                                        0,0);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(coreSwitch31).get(1).getPort().getId().intValue(),
                                                           logicalTest.getDevicePortByDevice(LRESwitch311).get(13).getPort().getId().intValue());

        Device cpe3111 =
                                logicalTest.addDevice("CPE311",
                                        Constants.MODEL_CPE_Cisco575LRECPE,
                                        "Otto Shmidta",
                                        "20",
                                        "135",
                                        "Cpe311",
                                        "Ukraine",
                                        "Kiev",
                                        0,0);
        logicalTest.addConnections(logicalTest.getDevicePortByDevice(LRESwitch311).get(0).getPort().getId().intValue(),
                                                           logicalTest.getDevicePortByDevice(cpe3111).get(1).getPort().getId().intValue());


       
        return null;
    }

    public List getAllSwitches(){
        return logicalTest.getModelsByType(Constants.MODELTYPE_SWITCH);
    }

    public List getPorts(){

       return logicalTest.getPorts((int)d.getId().intValue());
    }
}
